package com.randi.monitor.dto.service;

import com.randi.common.utils.MathFloatUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 内存信息
 *
 * @author randi
 */
@Data
@ApiModel(value = "Memory", description = "内存相关信息")
public class Memory {

    @ApiModelProperty(value = "总内存")
    private double total;

    @ApiModelProperty(value = "已用内存")
    private double used;

    @ApiModelProperty(value = "剩余内存")
    private double free;

    public double getTotal() {
        return MathFloatUtils.div(total, (1024 * 1024 * 1024), 2);
    }

    public double getUsed() {
        return MathFloatUtils.div(used, (1024 * 1024 * 1024), 2);
    }

    public double getFree() {
        return MathFloatUtils.div(free, (1024 * 1024 * 1024), 2);
    }

    public double getUsage() {
        return MathFloatUtils.mul(MathFloatUtils.div(used, total, 4), 100);
    }

}
